#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    string largestGoodInteger(string num) {
        int res = -1, n = num.size();
        for (int i = 2; i < n; i++)
        {
            if (num[i] == num[i - 1] && num[i - 1] == num[i - 2]) res = max(res, atoi(num.substr(i - 2, 3).c_str()));
        }
        if (res == -1) return "";
        else if (res == 0) return "000";
        else return string(to_string(res));
    }
};